package cn.liao.me;

import com.alibaba.fastjson.JSON;

import java.util.*;
import java.util.stream.Collectors;

public class MyTest {
    public static void main(String[] args) {
        Map<String, List<String>> result = new HashMap<>();
        List<String> lista = result.computeIfAbsent("a", key -> new ArrayList<>());
        lista.add("a1");
        lista.add("a1");
        lista.add("a2");
        lista.add("a3");
        lista.add("a3");

        List<String> listb = result.computeIfAbsent("b", key -> new ArrayList<>());
        listb.add("b1");
        listb.add("b1");
        listb.add("b2");
        listb.add("b3");
        listb.add("b3");

        System.out.println("before==>> " + JSON.toJSONString(result));

        //将map 中的key值中的list列表中的元素去重
        result.replaceAll((factoryType, implementations) -> implementations.stream().distinct()
                .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)));

        System.out.println("after==>> " + JSON.toJSONString(result));

        List<String> aKeyList = result.getOrDefault("a", Collections.emptyList());
        System.out.println("aKeyList==>> " + aKeyList);

        List<String> cKeyList = result.getOrDefault("c", Collections.emptyList());
        System.out.println("cKeyList==>> " + cKeyList);
/*
before==>> {"a":["a1","a1","a2","a3","a3"],"b":["b1","b1","b2","b3","b3"]}
after==>> {"a":["a1","a2","a3"],"b":["b1","b2","b3"]}
 */

    }
}
